function GAD_Midazolam_MI_pvalue_dist(Placeness_MetaData)
%% Get WT saline MI p-values ready for plotting
for n=1:size(Placeness_MetaData,2)
    if Placeness_MetaData(n).dose==0 && contains(Placeness_MetaData(n).genotype,'a5-i-WT') && contains(Placeness_MetaData(n).session, 'AM')
        WT_Saline_MI_pvalues(n,:)=Placeness_MetaData(n).MI_pvalues_proportion;
    end
end
for n=1:size(WT_Saline_MI_pvalues,1)
    if max(WT_Saline_MI_pvalues(n,:))==0
        WT_Saline_MI_pvalues(n,:)=nan;
    end
end


for n=1:size(WT_Saline_MI_pvalues,2)
    WT_Saline_MI_pvalues_Mean(1,n)=mean(WT_Saline_MI_pvalues(:,n),'omitnan');
end

for n=1:size(WT_Saline_MI_pvalues,2)
    WT_Saline_MI_pvalues_Err(1,n)=calculate_standard_error(WT_Saline_MI_pvalues(:,n));
end


%% Get WT MID 0.25mg/kg MI p-values ready for plotting
for n=1:size(Placeness_MetaData,2)
    if Placeness_MetaData(n).dose==0.25 && contains(Placeness_MetaData(n).genotype,'a5-i-WT') && contains(Placeness_MetaData(n).session, 'AM')
        WT_Mid025_MI_pvalues(n,:)=Placeness_MetaData(n).MI_pvalues_proportion;
    end
end
for n=1:size(WT_Mid025_MI_pvalues,1)
    if max(WT_Mid025_MI_pvalues(n,:))==0
        WT_Mid025_MI_pvalues(n,:)=nan;
    end
end


for n=1:size(WT_Mid025_MI_pvalues,2)
    WT_Mid025_MI_pvalues_Mean(1,n)=mean(WT_Mid025_MI_pvalues(:,n),'omitnan');
end

for n=1:size(WT_Mid025_MI_pvalues,2)
    WT_Mid025_MI_pvalues_Err(1,n)=calculate_standard_error(WT_Mid025_MI_pvalues(:,n));
end

%% Get WT Mid 0.75mg/kg MI p-values ready for plotting
for n=1:size(Placeness_MetaData,2)
    if Placeness_MetaData(n).dose==0.75 && contains(Placeness_MetaData(n).genotype,'a5-i-WT') && contains(Placeness_MetaData(n).session, 'AM')
        WT_Mid075_MI_pvalues(n,:)=Placeness_MetaData(n).MI_pvalues_proportion;
    end
end
for n=1:size(WT_Mid075_MI_pvalues,1)
    if max(WT_Mid075_MI_pvalues(n,:))==0
        WT_Mid075_MI_pvalues(n,:)=nan;
    end
end


for n=1:size(WT_Mid075_MI_pvalues,2)
    WT_Mid075_MI_pvalues_Mean(1,n)=mean(WT_Mid075_MI_pvalues(:,n),'omitnan');
end

for n=1:size(WT_Mid075_MI_pvalues,2)
    WT_Mid075_MI_pvalues_Err(1,n)=calculate_standard_error(WT_Mid075_MI_pvalues(:,n));
end

%% Get WT Mid 1.25mg/kg MI p-values ready for plotting
for n=1:size(Placeness_MetaData,2)
    if Placeness_MetaData(n).dose==1.25 && contains(Placeness_MetaData(n).genotype,'a5-i-WT') && contains(Placeness_MetaData(n).session, 'AM')
        WT_Mid125_MI_pvalues(n,:)=Placeness_MetaData(n).MI_pvalues_proportion;
    end
end
for n=1:size(WT_Mid125_MI_pvalues,1)
    if max(WT_Mid125_MI_pvalues(n,:))==0
        WT_Mid125_MI_pvalues(n,:)=nan;
    end
end


for n=1:size(WT_Mid125_MI_pvalues,2)
    WT_Mid125_MI_pvalues_Mean(1,n)=mean(WT_Mid125_MI_pvalues(:,n),'omitnan');
end

for n=1:size(WT_Mid125_MI_pvalues,2)
    WT_Mid125_MI_pvalues_Err(1,n)=calculate_standard_error(WT_Mid125_MI_pvalues(:,n));
end

%% Get WT Mid 2.5mg/kg MI p-values ready for plotting
for n=1:size(Placeness_MetaData,2)
    if Placeness_MetaData(n).dose==2.5 && contains(Placeness_MetaData(n).genotype,'a5-i-WT') && contains(Placeness_MetaData(n).session, 'AM')
        WT_Mid25_MI_pvalues(n,:)=Placeness_MetaData(n).MI_pvalues_proportion;
    end
end
for n=1:size(WT_Mid25_MI_pvalues,1)
    if max(WT_Mid25_MI_pvalues(n,:))==0
        WT_Mid25_MI_pvalues(n,:)=nan;
    end
end


for n=1:size(WT_Mid25_MI_pvalues,2)
    WT_Mid25_MI_pvalues_Mean(1,n)=mean(WT_Mid25_MI_pvalues(:,n),'omitnan');
end

for n=1:size(WT_Mid25_MI_pvalues,2)
    WT_Mid25_MI_pvalues_Err(1,n)=calculate_standard_error(WT_Mid25_MI_pvalues(:,n));
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Get MUT saline MI p-values ready for plotting
for n=1:size(Placeness_MetaData,2)
    if Placeness_MetaData(n).dose==0 && contains(Placeness_MetaData(n).genotype,'a5-i-KO') && contains(Placeness_MetaData(n).session, 'AM')
        MUT_Saline_MI_pvalues(n,:)=Placeness_MetaData(n).MI_pvalues_proportion;
    end
end
for n=1:size(MUT_Saline_MI_pvalues,1)
    if max(MUT_Saline_MI_pvalues(n,:))==0
        MUT_Saline_MI_pvalues(n,:)=nan;
    end
end


for n=1:size(MUT_Saline_MI_pvalues,2)
    MUT_Saline_MI_pvalues_Mean(1,n)=mean(MUT_Saline_MI_pvalues(:,n),'omitnan');
end

for n=1:size(MUT_Saline_MI_pvalues,2)
    MUT_Saline_MI_pvalues_Err(1,n)=calculate_standard_error(MUT_Saline_MI_pvalues(:,n));
end


%% Get MUT MID 0.25mg/kg MI p-values ready for plotting
for n=1:size(Placeness_MetaData,2)
    if Placeness_MetaData(n).dose==0.25 && contains(Placeness_MetaData(n).genotype,'a5-i-KO') && contains(Placeness_MetaData(n).session, 'AM')
        MUT_Mid025_MI_pvalues(n,:)=Placeness_MetaData(n).MI_pvalues_proportion;
    end
end
for n=1:size(MUT_Mid025_MI_pvalues,1)
    if max(MUT_Mid025_MI_pvalues(n,:))==0
        MUT_Mid025_MI_pvalues(n,:)=nan;
    end
end


for n=1:size(MUT_Mid025_MI_pvalues,2)
    MUT_Mid025_MI_pvalues_Mean(1,n)=mean(MUT_Mid025_MI_pvalues(:,n),'omitnan');
end

for n=1:size(MUT_Mid025_MI_pvalues,2)
    MUT_Mid025_MI_pvalues_Err(1,n)=calculate_standard_error(MUT_Mid025_MI_pvalues(:,n));
end

%% Get MUT Mid 0.75mg/kg MI p-values ready for plotting
for n=1:size(Placeness_MetaData,2)
    if Placeness_MetaData(n).dose==0.75 && contains(Placeness_MetaData(n).genotype,'a5-i-KO') && contains(Placeness_MetaData(n).session, 'AM')
        MUT_Mid075_MI_pvalues(n,:)=Placeness_MetaData(n).MI_pvalues_proportion;
    end
end
for n=1:size(MUT_Mid075_MI_pvalues,1)
    if max(MUT_Mid075_MI_pvalues(n,:))==0
        MUT_Mid075_MI_pvalues(n,:)=nan;
    end
end


for n=1:size(MUT_Mid075_MI_pvalues,2)
    MUT_Mid075_MI_pvalues_Mean(1,n)=mean(MUT_Mid075_MI_pvalues(:,n),'omitnan');
end

for n=1:size(MUT_Mid075_MI_pvalues,2)
    MUT_Mid075_MI_pvalues_Err(1,n)=calculate_standard_error(MUT_Mid075_MI_pvalues(:,n));
end

%% Get MUT Mid 1.25mg/kg MI p-values ready for plotting
for n=1:size(Placeness_MetaData,2)
    if Placeness_MetaData(n).dose==1.25 && contains(Placeness_MetaData(n).genotype,'a5-i-KO') && contains(Placeness_MetaData(n).session, 'AM')
        MUT_Mid125_MI_pvalues(n,:)=Placeness_MetaData(n).MI_pvalues_proportion;
    end
end
for n=1:size(MUT_Mid125_MI_pvalues,1)
    if max(MUT_Mid125_MI_pvalues(n,:))==0
        MUT_Mid125_MI_pvalues(n,:)=nan;
    end
end


for n=1:size(MUT_Mid125_MI_pvalues,2)
    MUT_Mid125_MI_pvalues_Mean(1,n)=mean(MUT_Mid125_MI_pvalues(:,n),'omitnan');
end

for n=1:size(MUT_Mid125_MI_pvalues,2)
    MUT_Mid125_MI_pvalues_Err(1,n)=calculate_standard_error(MUT_Mid125_MI_pvalues(:,n));
end

%% Get MUT Mid 2.5mg/kg MI p-values ready for plotting
for n=1:size(Placeness_MetaData,2)
    if Placeness_MetaData(n).dose==2.5 && contains(Placeness_MetaData(n).genotype,'a5-i-KO') && contains(Placeness_MetaData(n).session, 'AM')
        MUT_Mid25_MI_pvalues(n,:)=Placeness_MetaData(n).MI_pvalues_proportion;
    end
end
for n=1:size(MUT_Mid25_MI_pvalues,1)
    if max(MUT_Mid25_MI_pvalues(n,:))==0
        MUT_Mid25_MI_pvalues(n,:)=nan;
    end
end


for n=1:size(MUT_Mid25_MI_pvalues,2)
    MUT_Mid25_MI_pvalues_Mean(1,n)=mean(MUT_Mid25_MI_pvalues(:,n),'omitnan');
end

for n=1:size(MUT_Mid25_MI_pvalues,2)
    MUT_Mid25_MI_pvalues_Err(1,n)=calculate_standard_error(MUT_Mid25_MI_pvalues(:,n));
end

%% plotting MI p-values distribution
% define boundary
Upper_Bound=1;
Lower_Bound=0; 
Interval=0.05; 

figure
subplot(2,5,1)
bar((Lower_Bound+0.5*Interval:Interval:Upper_Bound),WT_Saline_MI_pvalues_Mean,1,'b','FaceAlpha',1);
ylim([0 0.3]);
xlabel('MI p-Values');
ylabel('Fraction of Cells');
hold on
er = errorbar((Lower_Bound+0.5*Interval:Interval:Upper_Bound),WT_Saline_MI_pvalues_Mean, [], WT_Saline_MI_pvalues_Err,'LineWidth',0.8);    
er.Color = [0 0 0];                            
er.LineStyle = 'None'; 
set(gca,'FontSize',15);
hold off
title('Saline','FontSize',20);

subplot(2,5,2)
bar((Lower_Bound+0.5*Interval:Interval:Upper_Bound),WT_Mid025_MI_pvalues_Mean,1,'b','FaceAlpha',0.8);
ylim([0 0.3]);
% xlabel('MI Shuffle Test p-values');
% ylabel('Fraction of Cells');
hold on
er = errorbar((Lower_Bound+0.5*Interval:Interval:Upper_Bound),WT_Mid025_MI_pvalues_Mean,[],WT_Mid025_MI_pvalues_Err,'LineWidth',0.8);    
er.Color = [0 0 0];                            
er.LineStyle = 'None';
set(gca,'FontSize',15);
hold off
title('0.25 mg/kg','FontSize',20);

subplot(2,5,3)
bar((Lower_Bound+0.5*Interval:Interval:Upper_Bound),WT_Mid075_MI_pvalues_Mean,1,'b','FaceAlpha',0.6);
ylim([0 0.3]);
% xlabel('MI Shuffle Test p-values');
% ylabel('Fraction of Cells');
hold on
er = errorbar((Lower_Bound+0.5*Interval:Interval:Upper_Bound),WT_Mid075_MI_pvalues_Mean,[],WT_Mid075_MI_pvalues_Err,'LineWidth',0.8);    
er.Color = [0 0 0];                            
er.LineStyle = 'None';
set(gca,'FontSize',15);
hold off
title('0.75 mg/kg','FontSize',20);

subplot(2,5,4)
bar((Lower_Bound+0.5*Interval:Interval:Upper_Bound),WT_Mid125_MI_pvalues_Mean,1,'b','FaceAlpha',0.5);
ylim([0 0.3]);
% xlabel('MI Shuffle Test p-values');
% ylabel('Fraction of Cells');
hold on
er = errorbar((Lower_Bound+0.5*Interval:Interval:Upper_Bound),WT_Mid125_MI_pvalues_Mean,[],WT_Mid125_MI_pvalues_Err,'LineWidth',0.8);    
er.Color = [0 0 0];                            
er.LineStyle = 'None';
set(gca,'FontSize',15);
hold off
title('1.25mg/kg','FontSize',20);

subplot(2,5,5)
bar((Lower_Bound+0.5*Interval:Interval:Upper_Bound),WT_Mid25_MI_pvalues_Mean,1,'b','FaceAlpha',0.4);
ylim([0 0.3]);
% xlabel('MI Shuffle Test p-values');
% ylabel('Fraction of Cells');
hold on
er = errorbar((Lower_Bound+0.5*Interval:Interval:Upper_Bound),WT_Mid25_MI_pvalues_Mean,[],WT_Mid25_MI_pvalues_Err,'LineWidth',0.8);    
er.Color = [0 0 0];                            
er.LineStyle = 'None';
set(gca,'FontSize',15);
hold off
title('2.5 mg/kg','FontSize',20);

subplot(2,5,6)
bar((Lower_Bound+0.5*Interval:Interval:Upper_Bound),MUT_Saline_MI_pvalues_Mean,1,'r','FaceAlpha',1);
ylim([0 0.3]);
xlabel('MI p-Values');
ylabel('Fraction of Cells');
hold on
er = errorbar((Lower_Bound+0.5*Interval:Interval:Upper_Bound),MUT_Saline_MI_pvalues_Mean, [], MUT_Saline_MI_pvalues_Err,'LineWidth',0.8);    
er.Color = [0 0 0];                            
er.LineStyle = 'None'; 
set(gca,'FontSize',15);
hold off
title('Saline','FontSize',20);

subplot(2,5,7)
bar((Lower_Bound+0.5*Interval:Interval:Upper_Bound),MUT_Mid025_MI_pvalues_Mean,1,'r','FaceAlpha',0.8);
ylim([0 0.3]);
% xlabel('MI Shuffle Test p-values');
% ylabel('Fraction of Cells');
hold on
er = errorbar((Lower_Bound+0.5*Interval:Interval:Upper_Bound),MUT_Mid025_MI_pvalues_Mean,[],MUT_Mid025_MI_pvalues_Err,'LineWidth',0.8);    
er.Color = [0 0 0];                            
er.LineStyle = 'None';
set(gca,'FontSize',15);
hold off
title('0.25 mg/kg','FontSize',20);

subplot(2,5,8)
bar((Lower_Bound+0.5*Interval:Interval:Upper_Bound),MUT_Mid075_MI_pvalues_Mean,1,'r','FaceAlpha',0.6);
ylim([0 0.3]);
% xlabel('MI Shuffle Test p-values');
% ylabel('Fraction of Cells');
hold on
er = errorbar((Lower_Bound+0.5*Interval:Interval:Upper_Bound),MUT_Mid075_MI_pvalues_Mean,[],MUT_Mid075_MI_pvalues_Err,'LineWidth',0.8);    
er.Color = [0 0 0];                            
er.LineStyle = 'None';
set(gca,'FontSize',15);
hold off
title('0.75 mg/kg','FontSize',20);

subplot(2,5,9)
bar((Lower_Bound+0.5*Interval:Interval:Upper_Bound),MUT_Mid125_MI_pvalues_Mean,1,'r','FaceAlpha',0.5);
ylim([0 0.3]);
% xlabel('MI Shuffle Test p-values');
% ylabel('Fraction of Cells');
hold on
er = errorbar((Lower_Bound+0.5*Interval:Interval:Upper_Bound),MUT_Mid125_MI_pvalues_Mean,[],MUT_Mid125_MI_pvalues_Err,'LineWidth',0.8);    
er.Color = [0 0 0];                            
er.LineStyle = 'None';
set(gca,'FontSize',15);
hold off
title('1.25mg/kg','FontSize',20);

subplot(2,5,10)
bar((Lower_Bound+0.5*Interval:Interval:Upper_Bound),MUT_Mid25_MI_pvalues_Mean,1,'r','FaceAlpha',0.4);
ylim([0 0.3]);
% xlabel('MI Shuffle Test p-values');
% ylabel('Fraction of Cells');
hold on
er = errorbar((Lower_Bound+0.5*Interval:Interval:Upper_Bound),MUT_Mid25_MI_pvalues_Mean,[],MUT_Mid25_MI_pvalues_Err,'LineWidth',0.8);    
er.Color = [0 0 0];                            
er.LineStyle = 'None';
set(gca,'FontSize',15);
hold off
title('2.5 mg/kg','FontSize',20);


end